package com.hibernate.persistence.lifecycle;

import java.util.Random;
import java.util.Scanner;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class SaveEntity {

	private static SessionFactory factory = new Configuration().configure().buildSessionFactory();
	private static Session session;
	private static Random rand = new Random();

	public static void main(String[] args) {
		System.out.println("---- Save Message ----");
		System.out.println("Enter msg : ");
		Scanner scan = new Scanner(System.in);
		session = factory.openSession();
		session.beginTransaction();
		String msg = scan.nextLine();
		Message message = new Message(msg);
		System.out.println("msg=" + msg);
		session.save("Message", message);
		session.getTransaction().commit();
		session.close();
		System.out.println("---- End Save Message ----");
	}

}
